package com.eet.juc.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * @author zheng.zhang
 */
public class ThreadPoolDemo1 {

    @SuppressWarnings("all")
    public static void main(String[] args) {
        // 单一线程的线程池
        // ExecutorService executor = Executors.newSingleThreadExecutor();
        // 固定数量的线程池
        // ExecutorService executor = Executors.newFixedThreadPool(5);
        // 可伸缩的线程池->遇强测强,遇弱则弱
        // ExecutorService executor = Executors.newCachedThreadPool();
        // 定时任务调度线程池
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(5);

        try {
            for (int i = 0; i < 20; i++) {
                executor.execute(() -> System.out.println(Thread.currentThread().getName() + " 执行OK"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executor.shutdown();
        }
    }
}
